package com.kzj.controller;

import com.kzj.annotation.OnCreate;
import com.kzj.annotation.OnEdit;
import com.kzj.common.result.Result;
import com.kzj.pojo.College;
import com.kzj.service.jpaRepository.CollegeJpaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/college")
public class CollegeController {
    @Autowired
    CollegeJpaRepository collegeService;
    @GetMapping
    public Result getAll()
    {
        return Result.success(collegeService.findAll());
    }
    @GetMapping("/{collegeId}")
    public Result getById(@PathVariable("collegeId")College college)
    {
        return Result.success(college);
    }
    @DeleteMapping("/{collegeId}")
    public Result deleteById(@PathVariable("collegeId") Long collegeId)
    {
        collegeService.deleteById(collegeId);
        return Result.success();
    }
    @PutMapping
    public Result update(@Validated(OnEdit.class) @RequestBody College college)
    {
        collegeService.save(college);
        return Result.success();
    }
    @PostMapping
    public Result add(@Validated(OnCreate.class) @RequestBody College college)
    {
        collegeService.save(college);
        return Result.success();
    }
}
